﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace IPC.Communication.Framework.Core.IMessage
{
    public class FetchWriteMessage : INetMessage
    {
        public int ProtocolHeadBytesLength
        {
            get
            {
                return 16;
            }
        }

        public byte[] HeadBytes
        {
            get;
            set;
        }

        public byte[] ContentBytes
        {
            get;
            set;
        }

        public byte[] SendBytes
        {
            get;
            set;
        }

        public int GetContentLengthByHeadBytes()
        {
            bool flag = this.HeadBytes[5] == 5 || this.HeadBytes[5] == 4;
            int result;
            if (flag)
            {
                result = 0;
            }
            else
            {
                bool flag2 = this.HeadBytes[5] == 6;
                if (flag2)
                {
                    bool flag3 = this.SendBytes == null;
                    if (flag3)
                    {
                        result = 0;
                    }
                    else
                    {
                        bool flag4 = this.HeadBytes[8] > 0;
                        if (flag4)
                        {
                            result = 0;
                        }
                        else
                        {
                            bool flag5 = this.SendBytes[8] == 1 || this.SendBytes[8] == 6 || this.SendBytes[8] == 7;
                            if (flag5)
                            {
                                result = ((int)this.SendBytes[12] * 256 + (int)this.SendBytes[13]) * 2;
                            }
                            else
                            {
                                result = (int)this.SendBytes[12] * 256 + (int)this.SendBytes[13];
                            }
                        }
                    }
                }
                else
                {
                    bool flag6 = this.HeadBytes[5] == 3;
                    if (flag6)
                    {
                        bool flag7 = this.HeadBytes[8] == 1 || this.HeadBytes[8] == 6 || this.HeadBytes[8] == 7;
                        if (flag7)
                        {
                            result = ((int)this.HeadBytes[12] * 256 + (int)this.HeadBytes[13]) * 2;
                        }
                        else
                        {
                            result = (int)this.HeadBytes[12] * 256 + (int)this.HeadBytes[13];
                        }
                    }
                    else
                    {
                        result = 0;
                    }
                }
            }
            return result;
        }

        public bool CheckHeadBytesLegal(byte[] token)
        {
            bool flag = this.HeadBytes == null;
            bool result;
            if (flag)
            {
                result = false;
            }
            else
            {
                bool flag2 = this.HeadBytes[0] == 83 && this.HeadBytes[1] == 53;
                result = flag2;
            }
            return result;
        }

        public int GetHeadBytesIdentity()
        {
            return (int)this.HeadBytes[3];
        }
    }
}
